package com.lxd.controller;

import java.util.List;

import com.lxd.entity.query.NotificationQuery;
import com.lxd.entity.po.Notification;
import com.lxd.entity.vo.PaginationResultVO;
import com.lxd.entity.vo.ResponseVO;
import com.lxd.service.NotificationService;
import com.lxd.utils.Constants;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 *  Controller
 */
@RestController("notificationController")
@RequestMapping("/notification")
public class NotificationController extends ABaseController{

	@Resource
	private NotificationService notificationService;
	/**
	 * 根据条件分页查询
	 */
	@RequestMapping("/loadDataList")
	public ResponseVO loadDataList(NotificationQuery query, HttpServletRequest request){
		PaginationResultVO<Notification> listByPage = notificationService.findListByPage(query,request.getHeader(Constants.HEADER_TOKEN));
		return getSuccessResponseVO(listByPage);
	}

	/**
	 * 新增
	 */
	@RequestMapping("/add")
	public ResponseVO add(Notification bean) {
		notificationService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增
	 */
	@RequestMapping("/addBatch")
	public ResponseVO addBatch(@RequestBody List<Notification> listBean) {
		notificationService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增/修改
	 */
	@RequestMapping("/addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(@RequestBody List<Notification> listBean) {
		notificationService.addOrUpdateBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@RequestMapping("/getNotificationById")
	public ResponseVO getNotificationById(Long id) {
		return getSuccessResponseVO(notificationService.getNotificationById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@RequestMapping(value = "/updateNotificationById")
	public ResponseVO updateNotificationById(@RequestBody Notification bean, Long id) {
		notificationService.updateNotificationById(bean,bean.getId());
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id删除
	 */
	@RequestMapping("/deleteNotificationById")
	public ResponseVO deleteNotificationById(Long id) {
		notificationService.deleteNotificationById(id);
		return getSuccessResponseVO(null);
	}
	@RequestMapping("/updateBatchIsRead")
	public ResponseVO UpdateBatchIsRead(@RequestBody List<Notification> listBean) {
		notificationService.addOrUpdateBatch(listBean);
		return getSuccessResponseVO(null);
	}
}